package edu.nwpu.utils;


import edu.nwpu.pojo.Order;

import java.util.HashMap;
import java.util.Map;

public abstract class OrderUtil {

    public static final int DELETED     = 0;
    public static final int WAIT_PAY    = 1;
    public static final int PAYED       = 2;
    public static final int DELIVERED   = 3;
    public static final int CANCELED    = 4;
    public static final int TAKEN       = 5;
    public static final int DELIVERING  = 6;

    private static final Map<Integer, String> STATUS_CODE_MAP = new HashMap<Integer, String>() {
        {
            put(DELETED,    "已删除");
            put(WAIT_PAY,   "等待付款");
            put(PAYED,      "已付款，等待接单");
            put(DELIVERED,  "已送达");
            put(CANCELED,   "已取消");
            put(TAKEN,      "已接单");
            put(DELIVERING, "正在配送");
        }
    };

    public static String getStatusCode(int statusCode) {
        if (STATUS_CODE_MAP.containsKey(statusCode)) {
            return STATUS_CODE_MAP.get(statusCode);
        }
        return "未知";
    }

    public static Map<String, Object> getOrderParamMap(Order order) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", order.getId());
        map.put("recvInfo", order.getRecvInfo());
        map.put("foods", order.getFoods());
        map.put("amount", order.getAmount());
        map.put("orderTime", order.getOrderTime());
        map.put("status", getStatusCode(order.getStatusCode()));
        return map;
    }

    public static boolean checkOrder(Order order) {
        return  ! (order.getFoods() == null
                || order.getFoods().size() == 0
                || order.getRecvInfo() == null
                || order.getRecvInfo().getId() == null
                || order.getUserId() == null);
    }
}
